package edu.jiefengli.course_selection_system.mapper;

import edu.jiefengli.course_selection_system.pojo.entity.Course;
import edu.jiefengli.course_selection_system.pojo.entity.CourseRecord;
import edu.jiefengli.course_selection_system.pojo.entity.User;
import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;

import java.util.List;

@Mapper
public interface CourseRecordMapper {
    @Select("select * from course_selection_record where student_id = #{id}")
    List<CourseRecord> getCourseRecordsById(Integer id);

    @Select("select * from course_selection_record")
    List<CourseRecord> getAllRecords();

    @Delete("delete from course_selection_record where course_id = #{courseId} and user_id = #{userId}")
    void removeCourseRecordById(Integer userId, Integer courseId);

    @Insert("insert into course_selection_record (student_id, course_id, status) values(#{studentId}, #{courseId}, 0)")
    void addCourseRecord(Integer studentId, Integer courseId);

    @Select("select count(*) from course_selection_record where student_id = #{studentId} and course_id = #{courseId}")
    int isSelectedCourseRecord(Integer studentId, Integer courseId);

    @Select("select * from user where id in (select student_id from course_selection_record where course_id = #{courseId})")
    List<User> getSelectedCourseStudent(int courseId);
}
